//字典解析
  dictdata['area'] = AreaListData;
var text =$('#num').text().replace(/[^0-9]/ig,"");
if(text=="0"){
    $('#list').hide();
    $('#empty').show();
}
//省市县
$.each(AreaListData, function (k, v) {
    if (v[1] == 0) {
        var option = "<option value='" + k + "'>" + v[0] + "</option>";
        $('#province').append(option);
    }
});
$('#province').change(function () {
    $('#city option:gt(0)').remove();
    $('#district option:gt(0)').remove();
    var sheng = $(this).val();
    $.each(AreaListData, function (k, v) {
        if (v[1] == sheng) {
            var option = "<option value='" + k + "'>" + v[0] + "</option>";
            $('#city').append(option);
        }
    });
});
$('#city').change(function () {
    $('#district option:gt(0)').remove();
    var shi = $(this).val();
    $.each(AreaListData, function (k, v) {
        if (v[1] == shi) {
            var option = "<option value='" + k + "'>" + v[0] + "</option>";
            $('#district').append(option);
        }
    });
});
var fengzi = $('#page_navigation a b').first();
var fengmu = $('#page_navigation a b').last();
//首页
    function first(){
        query(1);
        fengzi.text("1");
    }
//上一页    
    function previous(){
        var zi= parseInt(fengzi.text());
        var mu = parseInt(fengmu.text());
        if(zi>1){
        zi= zi-1;
        fengzi.text(zi);
        query(zi);
        }
    }
//下一页    
    function next(){
        var zi= parseInt(fengzi.text());
        var mu = parseInt(fengmu.text());
        if(zi<mu){
        zi= zi+1;
        fengzi.text(zi);
        query(zi);
        }
    }
//尾页    
    function last(){
        query(fengmu.text());
        fengzi.text(fengmu.text());
    }
    //跳转
  function jump(){
   var jump = $('[name=jump]').val();
   var mu = parseInt(fengmu.text());
   if(1<=jump&&jump<=mu){
        fengzi.text(jump);
        query(jump);
   }
  } 
$('button').click(function(){
    fengzi.text("1");
    query(1);
    num();
})
var h = $('#list ul'),text,sheng,shi,xian;
function query(page){
    h.empty();
    text="";
    new Ajax("/search_qiye_query.jsp").keyvalue($('form').serializeArray()).keyvalue("page",page).getJson(function(json){
        $.each(json,function(key,val){
//           sheng = AreaListData[val["shengid"]][0];
//           shi = AreaListData[val["shiid"]][0];
//           xian = AreaListData[val["xianid"]][0];
           var linkname =  val["linkname"];
           var telphone = val["telphone"];
           var main = val["mainbusiness"];
           if(main==null){
               main="";
           }
           if(linkname==null){
               linkname="";
           }
           if(telphone==null){
               telphone="";
           }
           text +="<li><a class='name' href='/supplier/home/"+val["myid"]+",target=blank'>"+val["corpname"]+"</a><h2>主营品类：<span id='sp'>"+main+"</span></h2><h3>所在地区：<span>"+val["userfulladress"]+"</h3><h4>联系人：<a class='company' href='#' target='blank'></a>"+linkname+"</h4><h5>联系方式：<span class='addr'>"+telphone+"</span></h5></li>"
        })
        h.html(text);
    })
}
function num(){
    new Ajax("/search_qiye_page.jsp").keyvalue($('#form').serializeArray()).get(function (json) {
        $('#num').text("共有" + json + "条");
        if (json == 0) {
            $('#empty').show();
            $('#page_navigation').hide();
        } else {
            $('#empty').hide();
            $('#page_navigation').show();
        }
        numb = Math.ceil(json.replace(/[^0-9]/ig, "") / 10);
        fengmu.text(numb);
    });
}



